Code Generation


The Developer Extensions for Microsoft Dynamics CRM 2013/2015 ("CRM Developer Extensions") provides an extension library (see "Code Generation Extension Library" below) for the CrmSvcUtil.exe code generation tool that is used to generate a data context class and data transfer objects (DTOs) for all Microsoft Dynamics CRM ("CRM") entities. In CRM, these are known as "early-bound" classes. This mechanism follows the same design pattern that SqlMetal implements in the entity framework. The data context class is responsible for all data operations and provides IQueryable interfaces for all entities in CRM. You can retrieve data by executing a LINQ query against the IQueryable entity set properties. You can change data by using the AddObject, DeleteObject, UpdateObject, and SaveChanges methods.

CrmSvcUtil.exe

This console application executable is located in the CRM SDK in the bin folder.
Usage: "CrmSvcUtil.exe extension usage and command-line parameters"

Code Generation Extension Library

Where the CRM SDK refers to the "extension library" for CrmSvcUtil.exe, it is referring to the class library file Microsoft.Xrm.Client.CodeGeneration.dll. You can use this extension to generate the data context and data transfer object classes for a CRM organization.

Filtering Generated Code

It's possible to control which entities, attributes and other objects and properties that the CrmSvcUtil application generates. See sample filtering code in the CRM SDK in file BasicFilteringService.cs.

ICodeWriterFilterService: Used to indicate whether a specific object or property should be generated. Called during the process of CodeDOM generation, assuming the default instance of ICodeGenerationService.

Generating Enum Statements for OptionSets (Picklists)

In the CRM SDK, see sample Visual Studio solution \SampleCode\CS\CrmSvcUtilExtensions\GeneratePicklistEnums

Links

Walkthrough: Build a console application that connects to Microsoft Dynamics CRM using developer extensions

Extending CrmSvcUtil (Filtering the generated classes)